all : getOneSite scan getNames buildIndex getIndex main 

CPP = g++
FLAGS = -Wall -O2 -g
INC = . 
LIB = -L.

common.o : common.cpp common.h
ftp.o : ftp.cpp ftp.h common.h
index.o : index.cpp index.h common.h
lock.o : lock.cpp lock.h common.h

getOneSite.o : getOneSite.cpp common.h ftp.h
scan.o : scan.cpp common.h ftp.h lock.h
getNames.o : getNames.cpp common.h ftp.h
buildIndex.o : buildIndex.cpp index.h common.h lock.h
getIndex.o : getIndex.cpp index.h common.h lock.h
webPage.o : webPage.cpp common.h lock.h
main.o : main.cpp common.h

.cpp.o:
	$(CPP) $(FLAGS) -I$(INC) -c $<

#####

getOneSite : getOneSite.o common.o ftp.o 
	$(CPP) $(FLAGS) $(LIB) $^ -o $@

scan : scan.o common.o ftp.o lock.o
	$(CPP) $(FLAGS) $(LIB) $^ -o $@ -lpthread

getNames : getNames.o common.o ftp.o
	$(CPP) $(FLAGS) $(LIB) $^ -o $@

buildIndex : buildIndex.o common.o index.o lock.o
	$(CPP) $(FLAGS) $(LIB) $^ -o $@

getIndex : getIndex.o common.o index.o lock.o
	$(CPP) $(FLAGS) $(LIB) $^ -o $@

webPage : webPage.o common.o lock.o
	$(CPP) $(FLAGS) $(LIB) $^ -o $@
 
main : main.o common.o
	$(CPP) $(FLAGS) $(LIB) $^ -o $@

#####

clean : 
	rm *.o *.tmp getOneSite scan getNames buildIndex getIndex webPage main -rf

bin : all
	mv getOneSite scan getNames buildIndex getIndex main ../bin

test_vsftpd : getOneSite
	./getOneSite 127.0.0.1 21 anonymous anonymous 1_1.tmp

test_xlight : getOneSite
	./getOneSite 127.0.0.1 9999 download download 1_2.tmp

test_scan : scan
	./scan sites_submitted sites 192.168.0.0 192.168.255.255 1000

test_getNames : getNames
	./getNames sites dataNames 50 

test_buildIndex : buildIndex
	./buildIndex dataNames dataIndex.cache dataIndex

test_getIndex : getIndex
	./getIndex dataIndex "eclipse pdf" out.tmp

test_webPage : webPage
	./webPage 9999 dataIndex sites_submitted bugs_reported

test_main : main
	./main

cp : all
	cp scan getNames getOneSite buildIndex getIndex main /usr/lib/cgi-bin

#####

#test_index.o : test_index.cpp
#	$(CPP) test_index.cpp -c
#
#test_index : test_index.o common.o
#	$(CPP) test_index.o common.o -o test_index
#
#testIndex : test_index
#	./test_index

#test_scan2 : scan
#	./scan sites_submitted sites 192.168.0.0 192.168.255.255 10000 1000
